package com.jgsu.farm.controller;

import com.github.pagehelper.PageInfo;
import com.jgsu.farm.entity.BiologyCategory;
import com.jgsu.farm.service.BiologyCategoryService;
import com.jgsu.farm.utils.CommonResult;
import com.jgsu.farm.utils.ResultCode;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @program: farm-system
 * @description: 植物分类表的表现层
 * @author: Mr.zuo
 * @create: 2019-12-17 21:08
 **/

@Slf4j
@RestController
@RequestMapping("farm/sysuser/biologycategory")
public class BiologyCategoryController {
    @Autowired
    BiologyCategoryService biologyCategoryService;

    /**
     *添加植物分类信息
     * */
    @PostMapping(value = "/add", produces = "application/json")
     public CommonResult biologyCategoryAdd(BiologyCategory biologycategory) {
          biologyCategoryService.addBiologyCategory(biologycategory);
          log.info("添加植物分类信息数据{}",biologycategory);
          return CommonResult.success(ResultCode.SUCCESS);
     }

     /**
      * 分页查询植物分类信息
      * */
     @GetMapping(produces = "application/json")
    public CommonResult<PageInfo<BiologyCategory>> findBiologyCategoryList(@RequestParam(value = "page",required = false,defaultValue = "1")int page
                ,@RequestParam(value = "pagesize",required = false,defaultValue = "10")int pagesize){
            PageInfo<BiologyCategory> listBiologyCategory = biologyCategoryService.findListBiologyCategory(page,pagesize);
            log.info("分页查询植物分类信息的第{}页每页{}条数据",page,pagesize);
            return CommonResult.success(listBiologyCategory);
     }

    @ApiOperation(value = "植物分类信息删除功能", notes = "删除单条数据")
    @DeleteMapping(value = "/delete", produces = "application/json")
    public CommonResult biologyCategoryDelete(@RequestParam("bioid") Integer bioid) {
        biologyCategoryService.deleteBioById(bioid);
        log.info("删除数据id为{}的植物分类信息",bioid);
        return CommonResult.success(ResultCode.SUCCESS);
    }

    @ApiOperation(value = "植物分类信息更新功能", notes = "更新某条数据")
    @PutMapping(value = "/update", produces = "application/json")
    public CommonResult biologyCategoryUpdate(BiologyCategory biologyCategory) {
         biologyCategoryService.updateBiologyCategory(biologyCategory);
         log.info("更新数据id为{}的植物分类信息",biologyCategory.getBioid());
         return CommonResult.success(ResultCode.SUCCESS);
     }
}
